<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
	      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
</head>
<body>
用户 <input type="text" id="user"/><br>
密码 <input type="password" id="pass"/><br>
 <input type="button" id="btn1" value="注册"/><br>
<input type="button" id="btn2" value="登录"/><br>
<script src="jquery.min.js"></script>
<script>
$(function () {
	$("#btn1").on('click',function () {
		$.ajax({
			url:'/reg',
			data:{
				user:$('#user').val(),
				pass:$('#pass').val()
			},
			success(res){
				res=JSON.parse(res);
				if(res.code){
					alert('注册失败'+res.msg)
				}else {
					alert("注册成功");
				}
			},
			error(err){
				alert('错了');
			}
		})
	});

	$("#btn2").on('click',function () {
		$.ajax({
			url:'/login',
			data:{
				user:$('#user').val(),
				pass:$('#pass').val()
			},
			success(res){
				res=JSON.parse(res);
				if(res.code){
					alert('登录失败'+res.msg)
				}else {
					alert("登录成功");
				}
			},
			error(err){
				alert('错了');
			}
		})
	});
});
</script>
</body>
</html>